/* 页面缓存 */


//定义变量
const state = {
    keepAliveComponents: [],
}

//获取
var getters = {
    getKeepAliveComponents(state) {
        return state.keepAliveComponents;
    }
}

//设置
const mutations = {
    setKeepAlive(state, component) {
        // 注：防止重复添加（当然也可以使用Set）
        !state.keepAliveComponents.includes(component) &&
        state.keepAliveComponents.push(component)
    },
    setNoKeepAlive (state, component) {
        const index = state.keepAliveComponents.indexOf(component)
        index !== -1 &&
        state.keepAliveComponents.splice(index, 1)
    }
}

//异步
const actions = {
    asyncAdd(context) {
        //模拟异步
        setTimeout(() => {
            context.commit("setCount", context.state.count + 1);
        }, 1000);
    }
}



export default {
    namespaced:true,
    state,
    getters,
    actions,
    mutations,
}